home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Toolbox / GetDragHiliteColor / Application.c next >
Encoding:
C/C++ Source or Header  |  1994-09-11  |  3.3 KB  |  182 lines  |  [TEXT/MPS ]

  1. #include <QuickDraw.h>
  2. #include <Dialogs.h>
  3. #include <Fonts.h>
  4. #include <Processes.h>
  5. #include <TextEdit.h>
  6. #include <Events.h>
  7. #include <Menus.h>
  8. #include <Memory.h>
  9. #include <Errors.h>
  10. #include <ToolUtils.h>
  11.  
  12. #ifdef __powerc
  13. QDGlobals qd;
  14. #endif
  15.  
  16.  
  17.  
  18. void InitApplication(void);
  19. void CreateNewWindow(void);
  20. void MainEventLoop(void);
  21. void MenuCommand(long whaHappened);
  22. void DoAboutBox(void);
  23.  
  24. void PreEventLoop(void);
  25. void PostEventLoop(void);
  26. pascal void DrawWindowContent(short, short, GDHandle, long);
  27. void DrawIt(WindowPtr win);
  28. void DoUpdate(WindowPtr thisWindow);
  29.  
  30. static Boolean gDone;
  31.  
  32.  
  33. /*-------------------------------------------------------------------------------------*/
  34.  
  35. void main()
  36. {
  37.  
  38.     InitApplication();
  39.     PreEventLoop();
  40.     MainEventLoop();
  41. }
  42.  
  43.  
  44. /*-------------------------------------------------------------------------------------*/
  45.  
  46. void InitApplication()
  47. {
  48.     Handle theMenu;
  49.  
  50.     // Toolbox initialization
  51.     MaxApplZone();
  52.     InitGraf(&qd.thePort);
  53.     InitFonts();
  54.     InitWindows();
  55.     InitMenus();
  56.     TEInit();
  57.     InitDialogs(nil);
  58.     InitCursor();
  59.     FlushEvents(0,everyEvent);
  60.     
  61.     // Application initialization
  62.     gDone = false;
  63.     
  64.     theMenu = GetNewMBar(128);
  65.     if ( theMenu == nil )
  66.         goto MenuStuffFailed;
  67.  
  68.     SetMenuBar(theMenu);
  69.     AddResMenu(GetMHandle(128), 'DRVR');
  70.     DrawMenuBar();
  71.  
  72.     return;
  73.     
  74. MenuStuffFailed:
  75.     // If the menu stuff failed, something just ain't right (most likely some 
  76.     // resources are missing.
  77.     gDone = true;
  78.     return;
  79.  
  80. }
  81.  
  82.  
  83. /*-------------------------------------------------------------------------------------*/
  84.  
  85. void DoAboutBox()
  86. {
  87.     (void) Alert(128, nil);
  88. }
  89.  
  90.  
  91. /*-------------------------------------------------------------------------------------*/
  92.  
  93. void MainEventLoop()
  94. {
  95.     EventRecord        theEvent;
  96.     WindowPtr        thisWindow;
  97.     short            clickArea;
  98.     Rect            screenRect;
  99.     long            menuResult;
  100.     char            charCode;
  101.  
  102.     while ( !gDone )
  103.     {
  104.         if ( WaitNextEvent(everyEvent, &theEvent, 0, nil) )
  105.         {
  106.             switch (theEvent.what)
  107.             {
  108.                 case mouseDown:
  109.                     clickArea = FindWindow(theEvent.where, &thisWindow);
  110.                     
  111.                     if (clickArea == inDrag)
  112.                     {
  113.                         screenRect = (**GetGrayRgn()).rgnBBox;
  114.                         DragWindow(thisWindow, theEvent.where, &screenRect);
  115.                     }
  116.                     else if ( clickArea == inContent )
  117.                     {
  118.                         if ( thisWindow != FrontWindow() )
  119.                             SelectWindow(thisWindow);
  120.                     }
  121.                     else if (clickArea == inGoAway)
  122.                     {
  123.                         if ( TrackGoAway(thisWindow, theEvent.where) )
  124.                             gDone = true;
  125.                     }
  126.                     else if ( clickArea == inMenuBar ) 
  127.                     {
  128.                         menuResult = MenuSelect(theEvent.where);
  129.                         if ( (menuResult  >> 16) != 0 )
  130.                         {
  131.                             MenuCommand(menuResult);
  132.                             HiliteMenu(0);
  133.                         }
  134.                     }
  135.                     break;
  136.                 case keyDown:
  137.                     charCode = theEvent.message & charCodeMask;
  138.  
  139.                     if ( (theEvent.modifiers & cmdKey) != 0 ) 
  140.                     {    
  141.                         menuResult = MenuKey(charCode);
  142.                 
  143.                         if ( (menuResult  >> 16) != 0 )
  144.                             MenuCommand(menuResult);
  145.                             
  146.                     } 
  147.                     break;
  148.                 case updateEvt:
  149.                     thisWindow = (WindowPtr)theEvent.message;    
  150.                     DoUpdate(thisWindow);
  151.                 
  152.                     break;
  153.                 
  154.             }
  155.         }
  156.     }
  157. }
  158.  
  159.  
  160.  
  161. /*-------------------------------------------------------------------------------------*/
  162.  
  163. void MenuCommand(long whaHappened)
  164. {
  165.     short    menuID, menuItem;
  166.     
  167.     menuID = (whaHappened >> 16);
  168.     menuItem = (whaHappened & 0xFFFF);
  169.     
  170.     if ( menuID == 128 )
  171.     {
  172.         if ( menuItem == 1)
  173.             DoAboutBox();
  174.     }
  175.     else if ( menuID == 129 )
  176.     {
  177.         if (menuItem == 1)
  178.             gDone = true;
  179.     }
  180. }
  181.  
  182.